Byte endianess is an attribute of data storage and retrieval where the storage and retrieval support multiple access sizes (e.g., 8-bit, 16-bit, 32-bit, 64-bit). Finer granularity accesses allow a programmer to see the order in which larger accesses store bytes in memory. Big-endian variables are stored in memory in the opposite byte order from little-endian variables. Little-endian variables are stored with the least significant byte in the lowest memory byte address. Big and little-endian variables containing the same value are identical when present in a processor register. It is only the order in memory that is different.
The order of bytes within 16-bit, 32-bit and 64-bit data is visible to the programmer. In the C programming language, the programmer can access bytes by using a union, a type of overlay data structure, or by casting a pointer to data of multiple bytes to a pointer to single bytes. Historically, these techniques were used to improve performance. Thus the same C/C++ code run on architectures of different endianness may produce different results. For example, for the C code: int i=0x12345678; and char c=*((char*)&i), the value of ‘c’ will be 0x12 if the code is compiled and run on a big-endian architecture, and it will be 0x78 if the code is compiled and run on a little-endian architecture.
A compiler with bi-endian technology allows compiling of source code that is originally developed for a big-endian architecture to run on a little-endian architecture. If the code is compiled in a special mode, in most cases it works the same way it would work if it was compiled and run on a big-endian architecture, i.e., ‘c’ is equal to 0x12 in the example above. This behavior is achieved by adding ‘byte swap’ operations before loads and stores into the memory of the data specified as big-endian.
A compiler with bi-endian technology is typically used to compile legacy code to run on modern little-endian architectures. A programmer typically marks all legacy code as big-endian, rather than determining whether each specific piece of data has to be big- or little-endian. So, the compiler adds byte swaps before loads and stores of the data, even when its endianness is not important to the programmer. This adversely impacts performance.